﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.HVAC.Properties;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using YArchitech.MEP;
using YArchitech.Revit;
using HYFamilyLibDataManager;

namespace YArchitech.HVAC
{
	public partial class LayAirTerminalFormNew : System.Windows.Forms.Form
	{
		public LayAirTerminalFormNew(ExternalCommandData ecd)
		{
			this.InitializeComponent();
			this.doc = ecd.Application.ActiveUIDocument.Document;
			this.sel = ecd.Application.ActiveUIDocument.Selection;
			//base.Icon = Resource.YArchitechIcon;
			this.GetAirTerminalData();
			this.initUserSetting();
		}

		public void GetAirTerminalData()
		{
			List<ListItem> allName = new SpaceFamilyDataReader().GetAllName("AirTerminal");
			this.NewDGVColumn("Value", "序号", "id", 60, this.dgvAirTerminal);
			this.NewDGVColumn("Name", "风口名称", "TName", 130, this.dgvAirTerminal);
			this.dgvAirTerminal.DataSource = allName;
			this.dgvAirTerminal.Columns["Tag"].Visible = false;
			if (this.dgvAirTerminal.Rows != null && this.dgvAirTerminal.Rows.Count > 0)
			{
				this.dgvAirTerminal.Rows[0].Selected = true;
				this.dgvAirTerminal_CellMouseClick(this.dgvAirTerminal, new DataGridViewCellMouseEventArgs(0, 0, 0, 0, new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0)));
			}
		}

		private void NewDGVColumn(string dataPropertyName, string headerText, string name, int width, DataGridView dgv)
		{
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
			dataGridViewTextBoxColumn.DataPropertyName = dataPropertyName;
			dataGridViewTextBoxColumn.HeaderText = headerText;
			dataGridViewTextBoxColumn.Name = name;
			dataGridViewTextBoxColumn.Width = width;
			dgv.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewTextBoxColumn
			});
		}

		private void dgvAirTerminal_CellContentClick(object sender, DataGridViewCellEventArgs e)
		{
		}

		private void dgvAirTerminal_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
		{
			if (e.RowIndex < 0)
			{
				return;
			}
			if (e.RowIndex == 2 || e.RowIndex == 0)
			{
				this.hytbTerminalHeight.Enabled = false;
				this.hytbThroatHeight.Enabled = false;
			}
			else
			{
				this.hytbTerminalHeight.Enabled = true;
				this.hytbThroatHeight.Enabled = true;
			}
			List<ListItem> infoById = new SpaceFamilyDataReader().GetInfoById("AirTerminal", int.Parse(this.dgvAirTerminal.Rows[e.RowIndex].Cells["Tag"].Value.ToString()));
			this.GetTerminalParamValue(infoById);
			this.CalSpeed();
			this.rowIndex = e.RowIndex;
			this.SetSideTerminalValue(this.rowIndex);
			this.SetControlsEnable(!this.BeSideTerminal);
			this.InitParam(this.airTerminalParaNew);
		}

		private void GetTerminalParamValue(List<ListItem> allInfo)
		{
			if (this.airTerminalParaNew == null)
			{
				this.airTerminalParaNew = new AirTerminalParamNew();
			}
			foreach (ListItem listItem in allInfo)
			{
				string name = listItem.Name;
				uint num = 0;//<PrivateImplementationDetails>.ComputeStringHash(name);
				if (num <= 2076255688u)
				{
					if (num <= 957100859u)
					{
						if (num != 917052505u)
						{
							if (num == 957100859u)
							{
								if (name == "TerminalWidth")
								{
									this.airTerminalParaNew.TerminalWidth = double.Parse(listItem.Value.Trim());
								}
							}
						}
						else if (name == "ThroatWidth")
						{
							this.airTerminalParaNew.ThroatWidth = double.Parse(listItem.Value.Trim());
						}
					}
					else if (num != 1494001562u)
					{
						if (num != 1905918934u)
						{
							if (num == 2076255688u)
							{
								if (name == "ThroatHeight")
								{
									this.airTerminalParaNew.ThroatHeight = double.Parse(listItem.Value.Trim());
								}
							}
						}
						else if (name == "TerminalHeight")
						{
							this.airTerminalParaNew.TerminalHeight = double.Parse(listItem.Value.Trim());
						}
					}
					else if (!(name == "Image"))
					{
					}
				}
				else if (num <= 2477681210u)
				{
					if (num != 2439411060u)
					{
						if (num == 2477681210u)
						{
							if (name == "TerminalThick")
							{
								this.airTerminalParaNew.TerminalThick = double.Parse(listItem.Value.Trim());
							}
						}
					}
					else if (name == "Image2D")
					{
						this.pb2D.Image = new Bitmap(listItem.Value);
					}
				}
				else if (num != 2770974846u)
				{
					if (num != 2894561144u)
					{
						if (num == 3788357144u)
						{
							if (name == "TerminalDrop")
							{
								this.airTerminalParaNew.Drop = double.Parse(listItem.Value.Trim());
							}
						}
					}
					else if (name == "ThroatDiameter")
					{
						this.airTerminalParaNew.ThroatDiameter = double.Parse(listItem.Value.Trim());
					}
				}
				else if (name == "TerminalDiameter")
				{
					this.airTerminalParaNew.TerminalDiameter = double.Parse(listItem.Value.Trim());
				}
			}
		}

		private void SetSideTerminalValue(int rowIndex)
		{
			string text = this.dgvAirTerminal.Rows[rowIndex].Cells["TName"].Value.ToString();
			if (text.Equals("侧风口") || text.Contains("侧风口"))
			{
				this.BeSideTerminal = true;
				return;
			}
			this.BeSideTerminal = false;
		}

		private void SetControlsEnable(bool beEnable = false)
		{
			this.btnArea.Enabled = beEnable;
			this.hytbOffset.Enabled = beEnable;
			if (beEnable)
			{
				this.btnAuto.Text = "自动布置";
				return;
			}
			this.btnAuto.Text = "沿管布置";
		}

		private void btnAlone_Click(object sender, EventArgs e)
		{
			this.InitLayType("Point");
			this.InitTerminalParam();
			this.FamilyLoad();
			if (this.fs == null && this.hy == 1)
			{
				YJKMessageBox.Show("您未选择当前项目族类型！");
				return;
			}
			base.DialogResult = DialogResult.OK;
		}

		private void btnArea_Click(object sender, EventArgs e)
		{
			LayAreaFormNew layAreaFormNew = new LayAreaFormNew(this.userSetting);
			if (layAreaFormNew.ShowDialog() == DialogResult.OK)
			{
				this.InitLayType(layAreaFormNew.connectType);
				this.InitTerminalParam();
				this.FamilyLoad();
				if (this.fs == null && this.hy == 1)
				{
					YJKMessageBox.Show("您未选择当前项目族类型！");
					return;
				}
				if (layAreaFormNew.connectType == "Line")
				{
					this.layLineParam = layAreaFormNew.layLineParameter;
				}
				else if (layAreaFormNew.connectType == "Rect")
				{
					this.layAreaParam = layAreaFormNew.layRectParameter;
				}
				else if (layAreaFormNew.connectType == "Mid")
				{
					this.layMidParam = layAreaFormNew.layMidParameter;
				}
				this.rectLayParas = layAreaFormNew.rectLayParas;
				base.DialogResult = DialogResult.OK;
			}
		}

		private void InitLayType(string layType)
		{
			if (layType == "Point")
			{
				this.layType = 0;
				return;
			}
			if (layType == "Auto")
			{
				this.layType = 5;
				return;
			}
			if (layType == "Line")
			{
				this.layType = 1;
				return;
			}
			if (layType == "Cross")
			{
				this.layType = 2;
				return;
			}
			if (layType == "Rect")
			{
				this.layType = 3;
				return;
			}
			if (!(layType == "Mid"))
			{
				return;
			}
			this.layType = 4;
		}

		private void FamilyLoad()
		{
			if (this.hy == 0)
			{
				this.fs = this.sfdr.GetFamilySymbolById(int.Parse(this.dgvAirTerminal.Rows[this.rowIndex].Cells["Tag"].Value.ToString()), "AirTerminal", this.doc, BuiltInCategory.OST_DuctTerminal);
			}
		}

		private void InitTerminalParam()
		{
			if (this.airTerminalParaNew == null)
			{
				this.airTerminalParaNew = new AirTerminalParamNew();
			}
			this.airTerminalParaNew.OffSet = double.Parse(this.hytbOffset.Text.Trim());
			this.airTerminalParaNew.Flow = double.Parse(this.hytbOneFlow.Text.Trim());
			this.airTerminalParaNew.Speed = double.Parse(this.hytbSpeed.Text.Trim());
			this.airTerminalParaNew.TerminalType = this.terminalType;
			this.CheckEndWidth = Convert.ToDouble(this.hytbTerminalWidth.Text.Trim()) / 609.6;
		}

		private void btnAuto_Click(object sender, EventArgs e)
		{
			this.InitLayType("Auto");
			if (this.BeSideTerminal)
			{
				LaySideAirTerminalLineForm laySideAirTerminalLineForm = new LaySideAirTerminalLineForm(this.userSetting);
				if (laySideAirTerminalLineForm.ShowDialog() == DialogResult.OK)
				{
					this.InitTerminalParam();
					this.FamilyLoad();
					if (this.fs == null && this.hy == 1)
					{
						YJKMessageBox.Show("您未选择当前项目族类型！");
						return;
					}
					this.laySideParam = laySideAirTerminalLineForm.layParameter;
					base.DialogResult = DialogResult.OK;
					return;
				}
			}
			else
			{
				if (this.layAutoParam == null)
				{
					this.layAutoParam = new LayAutoParameter();
				}
				this.layAutoParam.AllCount = int.Parse(this.hytbTerminalCount.Text.Trim());
				this.InitTerminalParam();
				this.FamilyLoad();
				if (this.fs == null && this.hy == 1)
				{
					YJKMessageBox.Show("您未选择当前项目族类型！");
					return;
				}
				base.DialogResult = DialogResult.OK;
			}
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void dgvAirTerminal_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
		{
		}

		private void pbArrowOut_MouseClick(object sender, MouseEventArgs e)
		{
			this.setArrowType("out");
		}

		private void pbArrowIn_MouseClick(object sender, MouseEventArgs e)
		{
			this.setArrowType("in");
		}

		private void pbArrowNone_MouseClick(object sender, MouseEventArgs e)
		{
			this.setArrowType("none");
		}

		private void pbArrowOut_Click(object sender, EventArgs e)
		{
		}

		private void btnGetFlow_Click(object sender, EventArgs e)
		{
		}

		private void hytbAllFlow_TextChanged(object sender, EventArgs e)
		{
			this.CalOneFlow();
		}

		private void hytbTerminalCount_TextChanged(object sender, EventArgs e)
		{
			this.CalOneFlow();
		}

		private void CalOneFlow()
		{
			if (this.hytbAllFlow.Text.Trim() != "" && this.hytbTerminalCount.Text.Trim() != "")
			{
				double num = 0.0;
				int num2 = 1;
				try
				{
					num = double.Parse(this.hytbAllFlow.Text.Trim());
					num2 = int.Parse(this.hytbTerminalCount.Text.Trim());
				}
				catch (Exception)
				{
				}
				if (num2 > 0)
				{
					this.hytbOneFlow.Text = double.Parse(StringTools.CutOffEfficacious((num / (double)num2).ToString(), 2)).ToString();
				}
			}
		}

		private void CalSpeed()
		{
			double num = 0.0;
			double num2 = 0.0;
			double num3 = 1.0;
			if (this.hytbOneFlow.Text.Trim() != "")
			{
				if (this.airTerminalParaNew.ThroatWidth > 0.0001 && this.airTerminalParaNew.ThroatHeight > 0.0001)
				{
					num2 = this.airTerminalParaNew.ThroatHeight * this.airTerminalParaNew.ThroatWidth / 1000000.0;
				}
				else if (this.airTerminalParaNew.ThroatDiameter > 0.0001)
				{
					num2 = Math.PI * this.airTerminalParaNew.ThroatDiameter * this.airTerminalParaNew.ThroatDiameter / 1000000.0;
				}
				try
				{
					num = double.Parse(this.hytbOneFlow.Text.Trim());
					num3 = double.Parse(this.hytxtAreaCoefficient.Text.Trim());
				}
				catch (Exception)
				{
				}
				if (num2 > 0.0 && num3 > 0.0)
				{
					this.hytbSpeed.Text = StringTools.CutOffEfficacious((num / num2 / (3600.0 * num3)).ToString(), 2);
				}
			}
		}

		private void hytbOneFlow_TextChanged(object sender, EventArgs e)
		{
			this.CalSpeed();
		}

		private void LayAirTerminalFormNew_Load(object sender, EventArgs e)
		{
			this.btnMore.Visible = false;
			if (this.hy == 0)
			{
				this.dgvAirTerminal_CellMouseClick(this.dgvAirTerminal, new DataGridViewCellMouseEventArgs(0, this.dgvAirTerminal.SelectedRows[0].Index, 0, 0, new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0)));
			}
		}

		private void initUserSetting()
		{
			string[] airTerminalText = this.userSetting.GetAirTerminalText();
			try
			{
				if (airTerminalText.Count<string>() >= 5)
				{
					foreach (object obj in ((IEnumerable)this.dgvAirTerminal.Rows))
					{
						DataGridViewRow dataGridViewRow = (DataGridViewRow)obj;
						if (dataGridViewRow.Cells["TName"].GetText() == airTerminalText[0])
						{
							this.dgvAirTerminal.Rows[dataGridViewRow.Index].Selected = true;
							this.dgvAirTerminal_CellMouseClick(this.dgvAirTerminal, new DataGridViewCellMouseEventArgs(0, dataGridViewRow.Index, 0, 0, new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0)));
							break;
						}
					}
					this.setArrowType(airTerminalText[1]);
					this.hytbOffset.Text = airTerminalText[2];
					this.hytbAllFlow.Text = airTerminalText[3];
					this.hytbTerminalCount.Text = airTerminalText[4];
					this.SetCurrentProjectTerminalType(airTerminalText[6]);
					this.dgvAirTerminal_CellMouseClick(this.dgvAirTerminal, new DataGridViewCellMouseEventArgs(0, this.dgvAirTerminal.SelectedRows[0].Index, 0, 0, new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0)));
					this.SetHYOrCurrProj(airTerminalText[5]);
					this.hytxtAreaCoefficient.Text = (string.IsNullOrEmpty(airTerminalText[7]) ? "1.0" : airTerminalText[7]);
				}
			}
			catch (Exception)
			{
			}
		}

		private void recordUserSetting()
		{
			string[] array = new string[]
			{
				"",
				"",
				"",
				"",
				"",
				"",
				"",
				""
			};
			try
			{
				if (array.Count<string>() >= 5)
				{
					array[0] = this.dgvAirTerminal.Rows[this.rowIndex].Cells["TName"].GetText().ToString();
					array[1] = this.terminalType;
					array[2] = this.hytbOffset.Text.ToString();
					array[3] = this.hytbAllFlow.Text.ToString();
					array[4] = this.hytbTerminalCount.Text.ToString();
					array[5] = this.GetHongOrCurrentProject();
					array[6] = this.GetCurrentProjectTerminalType();
					array[7] = this.hytxtAreaCoefficient.Text.ToString();
					this.userSetting.WriteAirTerminalText(array);
				}
			}
			catch (Exception)
			{
			}
		}

		private void setArrowType(string type)
		{
			if (type == "in")
			{
                this.pbArrowOut.BackColor = System.Drawing.Color.White;
                this.pbArrowIn.BackColor = System.Drawing.Color.RoyalBlue;
                this.pbArrowNone.BackColor = System.Drawing.Color.White;
				this.terminalType = "in";
				return;
			}
			if (type == "out")
			{
                this.pbArrowOut.BackColor = System.Drawing.Color.RoyalBlue;
                this.pbArrowIn.BackColor = System.Drawing.Color.White;
                this.pbArrowNone.BackColor = System.Drawing.Color.White;
				this.terminalType = "out";
				return;
			}
			if (!(type == "none"))
			{
                this.pbArrowOut.BackColor = System.Drawing.Color.RoyalBlue;
                this.pbArrowIn.BackColor = System.Drawing.Color.White;
                this.pbArrowNone.BackColor = System.Drawing.Color.White;
				this.terminalType = "out";
				return;
			}
            this.pbArrowOut.BackColor = System.Drawing.Color.White;
            this.pbArrowIn.BackColor = System.Drawing.Color.White;
            this.pbArrowNone.BackColor = System.Drawing.Color.RoyalBlue;
			this.terminalType = "none";
		}

		private void InitParam(AirTerminalParamNew airTerminalPara)
		{
			if (airTerminalPara != null)
			{
				if (!string.IsNullOrEmpty(airTerminalPara.TerminalWidth.ToString()) && airTerminalPara.TerminalWidth > 0.0001)
				{
					this.label1.Text = "风口宽度(mm):";
					this.hytbTerminalWidth.Text = airTerminalPara.TerminalWidth.ToString();
				}
				if (!string.IsNullOrEmpty(airTerminalPara.TerminalHeight.ToString()) && airTerminalPara.TerminalHeight > 0.0001)
				{
					this.label2.Enabled = true;
					this.hytbTerminalHeight.Text = airTerminalPara.TerminalHeight.ToString();
				}
				if (!string.IsNullOrEmpty(airTerminalPara.TerminalDiameter.ToString()) && airTerminalPara.TerminalDiameter > 0.0001)
				{
					this.label1.Text = "风口直径(mm):";
					this.label2.Enabled = false;
					this.hytbTerminalHeight.Enabled = false;
					this.hytbTerminalWidth.Text = airTerminalPara.TerminalDiameter.ToString();
				}
				this.hytbTerminalThick.Text = airTerminalPara.TerminalThick.ToString();
				if (!string.IsNullOrEmpty(airTerminalPara.ThroatWidth.ToString()) && airTerminalPara.ThroatWidth > 0.0001)
				{
					this.label4.Text = "喉口宽度(mm):";
					this.hytbThroatWidth.Text = airTerminalPara.ThroatWidth.ToString();
				}
				if (!string.IsNullOrEmpty(airTerminalPara.ThroatHeight.ToString()) && airTerminalPara.ThroatHeight > 0.0001)
				{
					this.label5.Enabled = true;
					this.hytbThroatHeight.Text = airTerminalPara.ThroatHeight.ToString();
				}
				if (!string.IsNullOrEmpty(airTerminalPara.ThroatDiameter.ToString()) && airTerminalPara.ThroatDiameter > 0.0001)
				{
					this.label4.Text = "喉口直径(mm):";
					this.label5.Enabled = false;
					this.hytbThroatHeight.Enabled = false;
					this.hytbThroatWidth.Text = airTerminalPara.ThroatDiameter.ToString();
				}
				this.hytbLoss.Text = airTerminalPara.Drop.ToString();
			}
		}

		private void hytb_TextChanged(object sender, EventArgs e)
		{
			if (!(sender is YJKTextBox))
			{
				return;
			}
			YJKTextBox hytextBox = sender as YJKTextBox;
			double num = double.Parse(hytextBox.Text.Trim());
			string name;
			if (num != 0.0)
			{
				if (this.label1.Text == "风口宽度(mm):" && !this.hytbTerminalHeight.Enabled)
				{
					name = hytextBox.Name;
					if (name == "hytbTerminalWidth")
					{
						this.hytbTerminalHeight.Text = num.ToString();
						return;
					}
					if (!(name == "hytbThroatWidth"))
					{
						return;
					}
					this.hytbThroatHeight.Text = num.ToString();
				}
				return;
			}
			YJKMessageBox.Show("数值不能是“0”，请重设！");
			name = hytextBox.Name;
			if (!(name == "hytbTerminalWidth"))
			{
				if (name == "hytbTerminalHeight")
				{
					this.hytbTerminalHeight.Text = this.airTerminalParaNew.TerminalHeight.ToString();
					return;
				}
				if (name == "hytbTerminalThick")
				{
					this.hytbTerminalThick.Text = this.airTerminalParaNew.TerminalThick.ToString();
					return;
				}
				if (!(name == "hytbThroatWidth"))
				{
					if (name == "hytbThroatHeight")
					{
						this.hytbThroatHeight.Text = this.airTerminalParaNew.ThroatHeight.ToString();
						return;
					}
					if (!(name == "hytbLoss"))
					{
						return;
					}
					this.hytbLoss.Text = this.airTerminalParaNew.Drop.ToString();
					return;
				}
				else
				{
					if (this.airTerminalParaNew.ThroatDiameter > 0.001)
					{
						this.hytbThroatWidth.Text = this.airTerminalParaNew.ThroatDiameter.ToString();
						return;
					}
					this.hytbThroatWidth.Text = this.airTerminalParaNew.ThroatWidth.ToString();
					return;
				}
			}
			else
			{
				if (this.airTerminalParaNew.TerminalDiameter > 0.001)
				{
					this.hytbTerminalWidth.Text = this.airTerminalParaNew.TerminalDiameter.ToString();
					return;
				}
				this.hytbTerminalWidth.Text = this.airTerminalParaNew.TerminalWidth.ToString();
				return;
			}
		}

		private void SaveTerminalParas()
		{
			this.airTerminalParaNew.Drop = double.Parse(this.hytbLoss.Text.Trim());
			if (this.label2.Enabled)
			{
				this.airTerminalParaNew.TerminalWidth = double.Parse(this.hytbTerminalWidth.Text.Trim());
				this.airTerminalParaNew.TerminalHeight = double.Parse(this.hytbTerminalHeight.Text.Trim());
			}
			else
			{
				this.airTerminalParaNew.TerminalDiameter = double.Parse(this.hytbTerminalWidth.Text.Trim());
			}
			this.airTerminalParaNew.TerminalThick = double.Parse(this.hytbTerminalThick.Text.Trim());
			if (this.label5.Enabled)
			{
				this.airTerminalParaNew.ThroatWidth = double.Parse(this.hytbThroatWidth.Text.Trim());
				this.airTerminalParaNew.ThroatHeight = double.Parse(this.hytbThroatHeight.Text.Trim());
			}
			else
			{
				this.airTerminalParaNew.ThroatDiameter = double.Parse(this.hytbThroatWidth.Text.Trim());
			}
			if (!this.checkParaValue())
			{
				return;
			}
			List<ListItem> list = new List<ListItem>();
			list.Add(new ListItem("TerminalWidth", this.airTerminalParaNew.TerminalWidth.ToString()));
			list.Add(new ListItem("TerminalHeight", this.airTerminalParaNew.TerminalHeight.ToString()));
			list.Add(new ListItem("TerminalDiameter", this.airTerminalParaNew.TerminalDiameter.ToString()));
			list.Add(new ListItem("TerminalThick", this.airTerminalParaNew.TerminalThick.ToString()));
			list.Add(new ListItem("ThroatWidth", this.airTerminalParaNew.ThroatWidth.ToString()));
			list.Add(new ListItem("ThroatHeight", this.airTerminalParaNew.ThroatHeight.ToString()));
			list.Add(new ListItem("ThroatDiameter", this.airTerminalParaNew.ThroatDiameter.ToString()));
			list.Add(new ListItem("TerminalDrop", this.airTerminalParaNew.Drop.ToString()));
			if (!this.sfdr.SetInfoById("AirTerminal", int.Parse(this.dgvAirTerminal.Rows[this.rowIndex].Cells["Tag"].Value.ToString()), list))
			{
				YJKMessageBox.Information("保存数据失败");
			}
			this.CalSpeed();
		}

		private bool checkParaValue()
		{
			if (this.label2.Enabled && this.label5.Enabled)
			{
				if (this.airTerminalParaNew.TerminalWidth <= this.airTerminalParaNew.ThroatWidth)
				{
					YJKMessageBox.Show("喉部宽度不得大于风口宽度，请\n重新设置喉部宽度值！");
					return false;
				}
				if (this.airTerminalParaNew.TerminalHeight <= this.airTerminalParaNew.ThroatHeight)
				{
					YJKMessageBox.Show("喉部高度不得大于风口高度，请\n重新设置喉部高度值！");
					return false;
				}
			}
			else if (this.airTerminalParaNew.TerminalDiameter <= this.airTerminalParaNew.ThroatDiameter)
			{
				YJKMessageBox.Show("喉部直径不得大于风口直径，请\n重新设置喉部直径！");
				return false;
			}
			return true;
		}

		private void groupBox5_Validated(object sender, EventArgs e)
		{
			this.SaveTerminalParas();
		}

		private void btnMore_Click(object sender, EventArgs e)
		{
			if (FamilyUtil.PathIni.ReadPath(this.doc.Application.VersionNumber) == "")
			{
				YJKMessageBox.Show("请先安装盈建科族立得。");
				return;
			}
			LayFamilyForm layFamilyForm = new LayFamilyForm(new HVACDataReader(this.doc).GetFamilyAllInfoTree("风口"), this.doc, "AirTerminal");
			if (layFamilyForm.ShowDialog() == DialogResult.OK)
			{
				this.fs = layFamilyForm.fs;
				this.layType = layFamilyForm.layType;
				this.layAreaParam = layFamilyForm.layAreaParam;
				this.layAutoParam = layFamilyForm.layAutoParam;
				this.layLineParam = layFamilyForm.layLineParam;
				this.layMidParam = layFamilyForm.layMidParam;
				if (this.airTerminalParaNew == null)
				{
					this.airTerminalParaNew = new AirTerminalParamNew();
				}
				this.airTerminalParaNew.OffSet = layFamilyForm.OffSet;
				this.rectLayParas = layFamilyForm.rectLays;
				base.DialogResult = DialogResult.OK;
				return;
			}
		}

		private void CheckedChanged(object sender, EventArgs e)
		{
			RadioButton radioButton = sender as RadioButton;
			if (radioButton.Checked)
			{
				this.tvwFamily.Nodes.Clear();
				this.BingTvwFamilys(this.GetFamilys(radioButton.Text));
				this.tvwFamily.ExpandAll();
				this.tvwFamily.SelectedNode = this.tvwFamily.Nodes[0];
				this.SetControlShowHide();
				this.GetCurrentTerminalParam();
				this.SetCurrentProjectTerminalParam();
				this.pb2D.Image = null;
			}
		}

		private List<Family> GetFamilys(string category)
		{
			IEnumerable<Element> enumerable = new FilteredElementCollector(this.doc).OfClass(typeof(Family)).ToElements();
			List<Family> list = new List<Family>();
			foreach (Element element in enumerable)
			{
				Family family = (Family)element;
				if (family.FamilyCategory.Id.IntegerValue == -2008013)
				{
					if (category == "其它")
					{
						if (!family.Name.Contains("方形") && !family.Name.Contains("矩形") && !family.Name.Contains("圆形") && !family.Name.Contains("侧风口"))
						{
							list.Add(family);
						}
					}
					else if (family.Name.Contains(category))
					{
						list.Add(family);
					}
				}
			}
			return list;
		}

		private void BingTvwFamilys(List<Family> familys)
		{
			new ElementId(-2008013);
			TreeNode treeNode = this.tvwFamily.Nodes.Add("风道末端");
			foreach (Family family in familys)
			{
				TreeNode tnFamily = treeNode.Nodes.Add(family.Id.ToString(), family.Name);
				this.BingTvwFamilySymbol(tnFamily, family);
			}
		}

		private void BingTvwFamilySymbol(TreeNode tnFamily, Family family)
		{
			foreach (ElementId elementId in family.GetFamilySymbolIds())
			{
				FamilySymbol familySymbol = this.doc.GetElement(elementId) as FamilySymbol;
				tnFamily.Nodes.Add(familySymbol.Id.IntegerValue.ToString(), familySymbol.Name);
			}
		}

		private void SetHYOrCurrProj(string hyOrCurrProj)
		{
			if (hyOrCurrProj == "hongye")
			{
				this.SelectedHy();
				return;
			}
			if (!(hyOrCurrProj == "currentProject"))
			{
				this.btnHy.PerformClick();
				return;
			}
			this.SelectedCurrentProject();
		}

		private string GetHongOrCurrentProject()
		{
			if (this.hy == 0)
			{
				return "hongye";
			}
			if (this.hy == 1)
			{
				return "currentProject";
			}
			return "";
		}

		private void SetCurrentProjectTerminalType(string currProjType)
		{
			if (currProjType == "square")
			{
				this.rdoSquare.Checked = true;
				return;
			}
			if (currProjType == "rectangle")
			{
				this.rdoRectangle.Checked = true;
				return;
			}
			if (currProjType == "circular")
			{
				this.rdoCircular.Checked = true;
				return;
			}
			if (currProjType == "sideDraught")
			{
				this.rdoSideDraught.Checked = true;
				return;
			}
			if (!(currProjType == "others"))
			{
				this.rdoSquare.Checked = true;
				return;
			}
			this.rdoOthers.Checked = true;
		}

		private string GetCurrentProjectTerminalType()
		{
			if (this.rdoSquare.Checked)
			{
				return "square";
			}
			if (this.rdoRectangle.Checked)
			{
				return "rectangle";
			}
			if (this.rdoCircular.Checked)
			{
				return "circular";
			}
			if (this.rdoSideDraught.Checked)
			{
				return "sideDraught";
			}
			if (this.rdoOthers.Checked)
			{
				return "others";
			}
			return "";
		}

		private void GetCurrentTerminalParam()
		{
			List<ListItem> allInfo = new List<ListItem>();
			if (this.rdoSquare.Checked)
			{
				allInfo = this.sfdr.GetInfoById("AirTerminal", 1);
			}
			else if (this.rdoRectangle.Checked)
			{
				allInfo = this.sfdr.GetInfoById("AirTerminal", 4);
			}
			else if (this.rdoCircular.Checked)
			{
				allInfo = this.sfdr.GetInfoById("AirTerminal", 2);
			}
			else if (this.rdoSideDraught.Checked)
			{
				allInfo = this.sfdr.GetInfoById("AirTerminal", 7);
			}
			else if (this.rdoOthers.Checked)
			{
				allInfo = this.sfdr.GetInfoById("AirTerminal", 4);
			}
			this.GetTerminalParamValue(allInfo);
		}

		private void SetCurrentProjectTerminalParam()
		{
			this.CalSpeed();
			if (this.rdoSideDraught.Checked)
			{
				this.BeSideTerminal = true;
			}
			else
			{
				this.BeSideTerminal = false;
			}
			this.SetControlsEnable(!this.BeSideTerminal);
			this.InitParam(this.airTerminalParaNew);
		}

		private void SetControlShowHide()
		{
			if (this.rdoSquare.Checked || this.rdoCircular.Checked)
			{
				this.hytbTerminalHeight.Enabled = false;
				this.hytbThroatHeight.Enabled = false;
				return;
			}
			this.hytbTerminalHeight.Enabled = true;
			this.hytbThroatHeight.Enabled = true;
		}

		private void tvwFamily_AfterSelect(object sender, TreeViewEventArgs e)
		{
			this.pb2D.Image = null;
            this.tvwFamily.SelectedNode.BackColor = System.Drawing.Color.DodgerBlue;
            this.tvwFamily.SelectedNode.ForeColor = System.Drawing.Color.White;
			if (e.Node.Nodes.Count == 0 && e.Node.Parent != null)
			{
				ElementId elementId = new ElementId(int.Parse(e.Node.Name));
				this.fs = (this.doc.GetElement(elementId) as FamilySymbol);
			}
			if (e.Node.Parent != null)
			{
				if (e.Node.Nodes.Count != 0)
				{
					ElementId elementId2 = new ElementId(int.Parse(e.Node.Nodes[0].Name));
					this.fs = (this.doc.GetElement(elementId2) as FamilySymbol);
				}
				string text = (e.Node.Nodes.Count == 0) ? Path.Combine(Product.FamilyImageLocation, "AirTerminal", e.Node.Parent.Text + "2D.bmp") : Path.Combine(Product.FamilyImageLocation, "AirTerminal", e.Node.Text + "2D.bmp");
				if (File.Exists(text))
				{
					this.pb2D.Image = new Bitmap(text);
					return;
				}
				text = HyProjectFamily.GetImageByFamily(this.fs.Family, "AirTerminal", this.doc);
				if (File.Exists(text))
				{
					this.pb2D.Image = new Bitmap(text);
					return;
				}
				this.pb2D.Image = new Bitmap(Path.Combine(Product.FamilyImageLocation, "default.bmp"));
			}
		}

		private void tvwFamily_BeforeSelect(object sender, TreeViewCancelEventArgs e)
		{
			if (this.tvwFamily.SelectedNode != null)
			{
                this.tvwFamily.SelectedNode.BackColor = System.Drawing.Color.White;
                this.tvwFamily.SelectedNode.ForeColor = System.Drawing.Color.Black;
			}
		}

		private void btnHy_Click(object sender, EventArgs e)
		{
			this.SelectedHy();
		}

		private void btnProj_Click(object sender, EventArgs e)
		{
			this.SelectedCurrentProject();
		}

		private void LayAirTerminalFormNew_FormClosed(object sender, FormClosedEventArgs e)
		{
			this.recordUserSetting();
		}

		private void SelectedHy()
		{
			this.hy = 0;
            this.btnHy.BackColor = System.Drawing.Color.White;
            this.btnProj.BackColor = System.Drawing.Color.Transparent;
			this.dgvAirTerminal.Visible = true;
			this.rdoSquare.Visible = false;
			this.rdoRectangle.Visible = false;
			this.rdoCircular.Visible = false;
			this.rdoSideDraught.Visible = false;
			this.rdoOthers.Visible = false;
			this.hygrpProject.Visible = false;
			this.tvwFamily.Visible = false;
			this.dgvAirTerminal_CellMouseClick(this.dgvAirTerminal, new DataGridViewCellMouseEventArgs(0, this.dgvAirTerminal.SelectedRows[0].Index, 0, 0, new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0)));
		}

		private void SelectedCurrentProject()
		{
			this.hy = 1;
            this.btnHy.BackColor = System.Drawing.Color.Transparent;
            this.btnProj.BackColor = System.Drawing.Color.White;
			this.dgvAirTerminal.Visible = false;
			this.rdoSquare.Visible = true;
			this.rdoRectangle.Visible = true;
			this.rdoCircular.Visible = true;
			this.rdoSideDraught.Visible = true;
			this.rdoOthers.Visible = true;
			this.tvwFamily.Visible = true;
			this.hygrpProject.Visible = true;
			this.fs = null;
			this.SetControlShowHide();
			this.GetCurrentTerminalParam();
			this.SetCurrentProjectTerminalParam();
			this.pb2D.Image = null;
			this.tvwFamily_AfterSelect(this.tvwFamily, new TreeViewEventArgs(this.tvwFamily.SelectedNode));
		}

		private void hytxtAreaCoefficient_Validated(object sender, EventArgs e)
		{
			if (this.regex.IsMatch(this.hytxtAreaCoefficient.Text.Trim()))
			{
				double num = 1.0;
				try
				{
					num = double.Parse(this.hytxtAreaCoefficient.Text.Trim());
				}
				catch (Exception)
				{
					this.hytxtAreaCoefficient.Text = "1.0";
				}
				if (num > 0.0)
				{
					this.CalSpeed();
					return;
				}
			}
			else
			{
				YJKMessageBox.Information("请输入有效的面积系数（0＜面积系数≤1所有保留一位有效数字的正数）！");
				this.hytxtAreaCoefficient.Text = "1.0";
				this.hytxtAreaCoefficient.Focus();
			}
		}

		private Document doc;

		private Selection sel;

		private int rowIndex;

		private string terminalType = "none";

		public FamilySymbol fs;

		public int isOnFace;

		public LayAreaParameter layAreaParam;

		public LayLineParameter layLineParam;

		public AirTerminalParamNew airTerminalParaNew;

		public LaySideParameter laySideParam;

		public LayMidParameter layMidParam;

		public LayAutoParameter layAutoParam;

		public int layType;

		public ListItemPlane planeParameter;

		public bool BeSideTerminal;

		public double CheckEndWidth;

		private HVACUserSetting userSetting = new HVACUserSetting();

		private SpaceFamilyDataReader sfdr = new SpaceFamilyDataReader();

		public RectLayParamers rectLayParas;

		private Regex regex = new Regex("^(0\\.[1-9]{1})|(1(\\.[0])?)$");

		private int hy;
	}
}
